﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FisheryPlatform.Entity;
using FisheryPlatform.Bussiness.Product;
using FisheryPlatform.Bussiness.Option;
using FisheryPlatform.Bussiness.Post;
using FisheryPlatform.SiteConfig;
using FisheryPlatform.Common.StaticCache;

namespace FisheryPlatform.Web.WWW
{
    public partial class Index : System.Web.UI.Page
    {
        #region
        private const string CacheKey_SellList = "Home.SellListCacheKey";
        private const string CacheKey_PurchaseList = "Home.PurchaseListCacheKey";
        private const string CacheKey_HomePostList = "Home.HomePostListCacheKey";
        private TimeSpan defaultCacheTimeSpan = new TimeSpan(0, 10, 0);

        protected List<ProductEntity> SellList = null;
        protected List<ProductEntity> PurchaseList = null;
        protected List<PostsEntity> HomePostList = null;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            #region
            var pageCount = 0;
            if (!CacheDataUtility.Intance.TryGet<List<ProductEntity>>(CacheKey_SellList, out SellList))
            {
                SellList = ProductManager.Search(" type=1 and status=" + (int)ProductStatusEnum.Publishing, 1, 10, out pageCount);
                CacheDataUtility.Intance.Set(CacheKey_SellList, SellList, defaultCacheTimeSpan);
            }

            if (!CacheDataUtility.Intance.TryGet<List<ProductEntity>>(CacheKey_PurchaseList, out PurchaseList))
            {
                PurchaseList = ProductManager.Search(" type=2 and status=" + (int)ProductStatusEnum.Publishing, 1, 10, out pageCount);
                CacheDataUtility.Intance.Set(CacheKey_PurchaseList, PurchaseList, defaultCacheTimeSpan);
            }

            if (!CacheDataUtility.Intance.TryGet<List<PostsEntity>>(CacheKey_HomePostList, out HomePostList))
            {
                HomePostList = PostManager.HomeList();
                CacheDataUtility.Intance.Set(CacheKey_HomePostList, HomePostList, defaultCacheTimeSpan);
            }
            #endregion
        }
    }
}